<template>
  <el-container
    direction = 'horizontal'
    class="home_box"
  >
    <el-aside>
      <el-scrollbar view-style="height:100%">
        <el-menu
          class="nav"
          :default-active = 'data.defaultActive'
          :background-color = 'data.color.theme[data.color.defaultTheme].menu.backgroundColor'
          :text-color = 'data.color.theme[data.color.defaultTheme].menu.textColor'
          :active-text-color = 'data.color.theme[data.color.defaultTheme].menu.activeTextColor'
          router
          v-loading="data.loading.loadingMenu"
        >
          <div class="title">
            <span>弹幕分析系统</span>
          </div>
          <el-menu-item v-for="(item, index) in data.menuArr" :key='index' :index="item.path">
            <span>{{ item.label }}</span>
          </el-menu-item>
        </el-menu>
      </el-scrollbar>
    </el-aside>
        <el-main style="padding: 0">
          <el-scrollbar>
            <router-view></router-view>
          </el-scrollbar>
        </el-main>
  </el-container>
</template>

<script lang="ts" setup>
import { onMounted, reactive } from 'vue-demi'
import http from '@/http/http'
import { useRoute } from 'vue-router'
import cache from '@/utils/cache'
const route = useRoute()
const data = reactive({
  color: {
    defaultTheme: 0,
    theme: [
      {
        menu: {
          titleColor: '#ccc',
          backgroundColor: '#666',
          textColor: '#ccc',
          activeTextColor: '#fff'
        },
        textColor: '#fff'
      }
    ]
  },
  menuArr: [
    {
      label: '',
      icon: '',
      path: ''
    }
  ],
  defaultActive: '/index',
  loading: {
    loadingMenu: true
  }
})
function getAdminMenuList () {
  data.loading.loadingMenu = true
  /**
   * 获取菜单列表
   */
  http.request({
    url: '/Admin/getAdminMenuList',
    method: 'POST',
    data: {
      successs: true
    }
  }).then(function (res) {
    if (res.status === 200) {
      data.menuArr = res.data
      cache.cache('menuArr', res.data)
      data.loading.loadingMenu = false
    } else {
      console.log(111)
      cache.cache('menuArr', data.menuArr)
    }
  }).catch(function () {
    cache.cache('menuArr', data.menuArr)
  }).finally(() => {
    data.menuArr = cache.cache('menuArr')
  })
}
function getColorList () {
  /**
     * 获取主题列表
     */
  http.request({
    url: '/Index/getColorList',
    method: 'POST'
  }).then(function (res) {
    if (res.status === 200) {
      cache.cache('color', res.data)
    } else {
      cache.cache('color', data.defaultColor)
    }
  }).catch(function () {
    cache.cache('color', data.defaultColor)
  }).finally(() => {
    data.color = cache.cache('color')
  })
}
onMounted(function () {
  /**
   * 获取菜单列表
   */
  getAdminMenuList()
  /**
   * 获取主题列表
   */
  getColorList()
  /**
   * 刷新时正确高亮当前所在菜单项
   */
  data.defaultActive = route.fullPath
})
</script>
<style lang="scss" scoped>
/**
  home_box .el-menu
  让菜单撑满屏幕
*/
.home_box {
  position: absolute;
  width: 100%;
  height: 100%;
}
.el-aside {
  box-shadow: 2px 0px 10px 0 rgba(0, 0, 0, 0.15); // 阴影
}
.el-menu {
  min-height:100%;
}
/**
  .title
  标题
*/
.title {
  text-align: center;
  height: 50px;
  line-height: 50px;
  color: v-bind('data.color.theme[data.color.defaultTheme].menu.titleColor');
}
</style>
